package com.bootdo.order.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.order.domain.ReplenishmentOrderDetailDO;
import com.bootdo.order.service.ReplenishmentOrderDetailService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
/**
 * 补货单表详情
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-02-02 17:39:58
 */
@Transactional
@Controller
@RequestMapping("/order/replenishmentOrderDetail")
public class ReplenishmentOrderDetailController {
	@Autowired
	private ReplenishmentOrderDetailService replenishmentOrderDetailService;
	
	@GetMapping()
	//@RequiresPermissions("order:replenishmentOrderDetail:replenishmentOrderDetail")
	String ReplenishmentOrderDetail(HttpServletRequest request){
        return request.getAttribute("i18n")+ "order/replenishmentOrderDetail/replenishmentOrderDetail";
	}
	
	@ResponseBody
	@GetMapping(value="/list",produces = "application/json; charset=UTF-8")
	//@RequiresPermissions("order:replenishmentOrderDetail:replenishmentOrderDetail")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ReplenishmentOrderDetailDO> replenishmentOrderDetailList = replenishmentOrderDetailService.list(query);
		int total = replenishmentOrderDetailService.count(query);
		PageUtils pageUtils = new PageUtils(replenishmentOrderDetailList, total);
		return pageUtils;
	}
	
	@GetMapping(value="/add",produces = "application/json; charset=UTF-8")
	//@RequiresPermissions("order:replenishmentOrderDetail:add")
	String add(HttpServletRequest request){
        return request.getAttribute("i18n")+  "order/replenishmentOrderDetail/add";
	}

	@GetMapping(value = "/edit/{id}",produces = "application/json; charset=UTF-8")
	//@RequiresPermissions("order:replenishmentOrderDetail:edit")
	String edit(@PathVariable("id") Long id,Model model,HttpServletRequest request){
		ReplenishmentOrderDetailDO replenishmentOrderDetail = replenishmentOrderDetailService.get(id);
		model.addAttribute("replenishmentOrderDetail", replenishmentOrderDetail);
        return request.getAttribute("i18n")+ "order/replenishmentOrderDetail/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping(value = "/save",produces = "application/json; charset=UTF-8")
    //@RequiresPermissions("order:replenishmentOrderDetail:add")
	public R save( ReplenishmentOrderDetailDO replenishmentOrderDetail){
		if(replenishmentOrderDetailService.save(replenishmentOrderDetail)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping(value = "/update",produces = "application/json; charset=UTF-8")
    //@RequiresPermissions("order:replenishmentOrderDetail:edit")
	public R update( ReplenishmentOrderDetailDO replenishmentOrderDetail){
		replenishmentOrderDetailService.update(replenishmentOrderDetail);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping(value = "/remove",produces = "application/json; charset=UTF-8")
	@ResponseBody
	//@RequiresPermissions("order:replenishmentOrderDetail:remove")
	public R remove( Long id){
		if(replenishmentOrderDetailService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( value = "/batchRemove",produces = "application/json; charset=UTF-8")
	@ResponseBody
    //@RequiresPermissions("order:replenishmentOrderDetail:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		replenishmentOrderDetailService.batchRemove(ids);
		return R.ok();
	}
	
}
